<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
  <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
  <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
</head>
<style> 
	.yanshi {
			height: 38px;
		    line-height: 1.3;
		    line-height: 38px\9;
		    border: 1px solid #e6e6e6;
		    background-color: #fff;
		    border-radius: 2px;
		    width: 211px;
		}
</style>
<body style="padding:10px;">
  <div class="tplay-body-div"> 
      <div class="layui-tab">
        <ul class="layui-tab-title">
          <li><a href="{:url('admin/store/emp')}" class="a_menu">员工管理</a></li>
          <li class="layui-this">员工编辑</li>
        </ul>
      </div>
    <form class="layui-form" id="admin">

      <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-inline">
          <input name="name" lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input" type="text" {notempty name="$info.emp.name"}value="{$info.emp.name}"{/notempty}>
        </div>
      </div>
      
      <div class="layui-form-item">
        <label class="layui-form-label">电话</label>
        <div class="layui-input-inline">
          <input name="tel" id="tel" lay-verify="required" placeholder="请输入电话" autocomplete="off" class="layui-input" type="text" {notempty name="$info.emp.tel"}value="{$info.emp.tel}"{/notempty}>
        </div>
      </div>
      
      <div class="layui-form-item">
        <label class="layui-form-label">登录账号 </label>
        <div class="layui-input-inline">
          <input name="loginname" lay-verify="required" placeholder="请输入登录账号" autocomplete="off" class="layui-input" type="text" {notempty name="$info.emp.loginname"}value="{$info.emp.loginname}"{/notempty}>
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label">登录密码</label>
        <div class="layui-input-inline">
          <input name="password" id="password" placeholder="请输入登录密码" autocomplete="off" class="layui-input" type="text">
        </div>
      </div>
      
      <div class="layui-form-item">
        <label class="layui-form-label">操作密码</label>
        <div class="layui-input-inline">
          <input name="oppass" id="oppass" placeholder="请输入操作密码" autocomplete="off" class="layui-input" type="text">
        </div>
      </div>
      
      <div class="layui-form-item">
        <label class="layui-form-label">角色</label>
        <div class="layui-input-inline">
          <select name="role_name_id" lay-filter="aihao" lay-verify="required" lay-search>
            <option value="">请选择角色</option>
            {volist name="info['hyjt_admin_cate']" id="vo"}
            <option value="{$vo.id}" {notempty name="$info.emp.role_name_id"}{eq name="$info.emp.role_name_id" value="$vo.id"} selected=""{/eq}{/notempty}>{$vo.name}</option>
            {/volist}
          </select>
        </div>
      </div>
      
      <div class="layui-form-item">
        <label class="layui-form-label">所属门店</label>
        <div class="layui-input-inline">
          <select onchange="select_trade(this);" lay-ignore class="yanshi" name="store_name_id" lay-filter="aihao" lay-verify="required" lay-search>
            <option value="">请选择门店</option>
            {volist name="info['hyjt_store']" id="vo"}
            <option value="{$vo.id}" {notempty name="$info.emp.store_name_id"}{eq name="$info.emp.store_name_id" value="$vo.id"} selected=""{/eq}{/notempty}>{$vo.store_name}</option>
            {/volist}
          </select>
        </div>
      </div>
      
      <div class="layui-form-item">
        <label class="layui-form-label">所属分组</label>
        <div class="layui-input-inline">
          <select lay-ignore class="yanshi" id="group_name_id" name="group_name_id" lay-filter="aihao" lay-verify="required" lay-search>
           <option value="">请选择分组</option>
            {volist name="info['hyjt_group']" id="vo"}
            <option value="{$vo.id}" {notempty name="$info.emp.group_name_id"}{eq name="$info.emp.group_name_id" value="$vo.id"} selected=""{/eq}{/notempty}>{$vo.group}</option>
            {/volist}
          </select>
        </div>
      </div>

      
      {notempty name="$info.emp"}
      <input type="hidden" name="id" value="{$info.emp.id}">
      {/notempty}
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn" lay-submit lay-filter="admin">立即提交</button>
          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
      </div>
      
    </form>


    <script src="__PUBLIC__/layui/layui.js"></script>
    <script src="__PUBLIC__/jquery/jquery.min.js"></script>
    <script>
        var message;
        layui.config({
            base: '__JS__/',
            version: '1.0.1'
        }).use(['app', 'message'], function() {
            var app = layui.app,
                $ = layui.jquery,
                layer = layui.layer;
            //将message设置为全局以便子页面调用
            message = layui.message;
            //主入口
            app.set({
                type: 'iframe'
            }).init();
        });
    </script>
    <script>
      layui.use(['layer', 'form'], function() {
          var layer = layui.layer,
              $ = layui.jquery,
              form = layui.form;
          $(window).on('load', function() {
              form.on('submit(admin)', function(data) {
              	var password = $('#password').val();
              	var oppass = $('#oppass').val();
              	var phone = $("#tel").val(); 
								var reg = /^1[3|4|5|6|7|8|9][0-9]{9}$/; //验证规则 
								if(!reg.test(phone)) {
									layer.msg('手机号码格式不正确'); 
									return;
								}
              	if(password.trim()){
              		if(password.length < 6 || password.length > 8){
              			layer.msg('登录密码请填写6~8位的密码');
              			return;
              		}
              	}
              	if(oppass.trim()){
              		if(oppass.length < 6 || oppass.length > 8){
              			layer.msg('操作密码请填写6~8位的密码');
              			return;
              		}
              	}
                  $.ajax({
                      url:"{:url('admin/store/publishemp')}",
                      data:$('#admin').serialize(),
                      type:'post',
                      async: false,
                      success:function(res) {
                          if(res.code == 1) {
                              layer.alert(res.msg, function(index){
                                location.href = res.url;
                              })
                          } else {
                              layer.msg(res.msg);
                          }
                      }
                  })
                  return false;
              });
          });
      });
      
      layui.use(['layer', 'form'], function() {
      	  var layer = layui.layer,
              form = layui.form;
                //自定义验证规则
              form.verify({
              pass: [/^[\S]{6,8}$/,'密码必须6到8位，且不能出现空格']
          });
      });    
      
      function select_trade(obj){
				var store_name_id=$(obj).val();
				var lay = layer.load(0, {shade: false,time: 1000});
				$.ajax({
						type: 'post',
						url: "{:url('store/get_store')}",
						data: {
							store_name_id:store_name_id
						},
						success: function(data) {
							var list=data.data;
							if(list != ''){ 
								var html="";
								for(var i=0;i<list.length;i++){
									var trade=list[i];  
									html+="<option value="+trade['id']+" >"+trade['group']+"</option>"; 
								}
							}else{ 
								html = "<option value='0'>请选择所属分组</option>";
							}
							$("#group_name_id").html(html);
						}
				})
				
			}
    </script>
    </div>
</body>
</html>